<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>回收站列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/boxicons@2.1.4/css/boxicons.min.css" rel="stylesheet">
    <style>
        .station-card {
            transition: transform 0.3s ease;
            margin-bottom: 1rem;
        }
        .station-card:hover {
            transform: translateY(-5px);
        }
        .status-badge {
            position: absolute;
            top: 10px;
            right: 10px;
        }
    </style>
</head>
<body>
    <div class="container mt-4">
        <div class="row">
            <div class="col-12">
                <h2 class="mb-4">回收站列表</h2>
            </div>
        </div>

        <div class="row">
            <!-- 搜索表单 -->
            <div class="col-12 mb-4">
                <div class="card">
                    <div class="card-body">
                        <form id="searchForm" class="row g-3">
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="name" placeholder="回收站名称">
                            </div>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="address" placeholder="地址">
                            </div>
                            <div class="col-md-4">
                                <button type="submit" class="btn btn-primary me-2">搜索</button>
                                <button type="reset" class="btn btn-secondary">重置</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- 回收站列表 -->
            <div class="col-12">
                <div class="row" id="stationList">
                    <div th:each="station : ${stations}" class="col-md-6 col-lg-4">
                        <div class="card station-card">
                            <div class="card-body">
                                <span th:class="${station.status == 1 ? 'badge bg-success' : 'badge bg-danger'} + ' status-badge'"
                                      th:text="${station.status == 1 ? '营业中' : '已关闭'}">
                                </span>
                                <h5 class="card-title" th:text="${station.name}">回收站名称</h5>
                                <p class="card-text">
                                    <i class="bx bx-map"></i>
                                    <span th:text="${station.address}">回收站地址</span>
                                </p>
                                <p class="card-text">
                                    <i class="bx bx-phone"></i>
                                    <span th:text="${station.contactPhone}">联系电话</span>
                                </p>
                                <p class="card-text">
                                    <i class="bx bx-time"></i>
                                    <span th:text="${station.businessHours}">营业时间</span>
                                </p>
                                <p class="card-text" th:if="${station.acceptableItems}">
                                    <i class="bx bx-package"></i>
                                    <span th:text="${station.acceptableItems}">可回收物品</span>
                                </p>
                                <button class="btn btn-primary btn-sm mt-2" 
                                        th:onclick="'navigateToStation(' + ${station.latitude} + ',' + ${station.longitude} + ')'">
                                    <i class="bx bx-navigation"></i> 导航
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        function navigateToStation(lat, lng) {
            // 使用高德地图导航
            window.open(`https://uri.amap.com/navigation?to=${lng},${lat}&mode=car&policy=1&src=myapp&callnative=0`);
        }

        document.getElementById('searchForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const formData = new FormData(this);
            const params = new URLSearchParams();
            
            for (let pair of formData.entries()) {
                if (pair[1]) {
                    params.append(pair[0], pair[1]);
                }
            }
            
            window.location.href = '/stations?' + params.toString();
        });
    </script>
</body>
</html> 